package com.lyc.campuslife.controller;


import com.lyc.campuslife.dto.Result;
import com.lyc.campuslife.dto.UserDTO;
import com.lyc.campuslife.service.IFollowService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import static com.lyc.campuslife.utils.HttpRequestConstants.USER_INFO;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lyc
 * @since 2024-07-04
 */
@RestController
@RequestMapping("/follow")
public class FollowController {
    @Resource
    private IFollowService followService;
    //关注/取关
    @PutMapping("/{id}/{isFollow}")
    public Result follow(@PathVariable("id") Long followUserId, @PathVariable("isFollow") Boolean isFollow, HttpServletRequest request) {
        UserDTO userDTO = (UserDTO)request.getAttribute(USER_INFO);
        Long userId = userDTO.getId();
        return followService.follow(followUserId, isFollow,userId);
    }
    //判断是否关注该用户
    @GetMapping("/or/not/{id}")
    public Result isFollow(@PathVariable("id") Long followUserId, HttpServletRequest request) {
        UserDTO userDTO = (UserDTO)request.getAttribute(USER_INFO);
        Long userId = userDTO.getId();
        return followService.isFollow(followUserId,userId);
    }
    //共同关注
    @GetMapping("/common/{id}")
    public Result followCommons(@PathVariable("id") Long id, HttpServletRequest request){
        UserDTO userDTO = (UserDTO)request.getAttribute(USER_INFO);
        Long userId = userDTO.getId();
        return followService.followCommons(id,userId);
    }
}
